#include "stdafx.h"
#include "cppflibinc.h"


using namespace cppflib;

/**
 *  This is to demonstrate how to new and delete a custom class which is 
 *  not derived from BaseObject but can still be added to Auto Release Pool safely
 */
class MyCustomClass
{
private:
   int arraySize;
   char * pArray;

public:
   MyCustomClass()
   {
      arraySize = 24;
      pArray = (char*)::MRP_Calloc(arraySize, sizeof(char));
   }

   ~MyCustomClass()
   {
      if (arraySize)
         ::MRP_Release(pArray);
   }

   void DoSomething()
   {
      for (int i = 0 ; i < arraySize; ++i)
         pArray[i] = 'c';
   }

   /**
    *  Provide an explicit function to do clean up job before this instance is deleted
    */
   static void DtorFunc(void *p)
   {
      MyCustomClass *t = reinterpret_cast<MyCustomClass*>(p);
      t->~MyCustomClass();
   }
};


static void TestNewRelease(void)
{
  cppmempool::MemPoolWrap localPool;

   // new the instance and provide the dtor as well
   MyCustomClass *pInst = new (&MyCustomClass::DtorFunc) MyCustomClass();
   pInst->DoSomething();

}

void TestCustomClass(void)
{

   TestNewRelease();

}
